import { S_CELL_GS_WIDTH } from "./GameGSDefine";
// import { EventKey } from "../common/Key";
import { EventKey } from "../common_for_guosheng/Key";

cc.Class({
    extends: cc.Component,

    properties: {
        label: cc.Label,
    },

    // onLoad () {},

    init(score, x, y, targetPos) {
        this.targetPos = targetPos;
        this.label.string = score;
        this.updateFuckPosition(x, y);

        let time = F.Utils.getDistance(this.node.position,targetPos) / 1000 * 0.5;
        cc.tween(this.node)
            .delay(0.5)
            .to(time, { position: this.targetPos }, { easing: 'sineIn' })
            .call(() => {
                F.Utils.putPoolFuckNode('nodePoolScore', this.node);
                F.OnEvent.fire(EventKey.EVENT_ADD_SCORE, { score: score });
            })
            .start();
    },

    // 更新位置
    updateFuckPosition(x, y) {
        let cellX = x * S_CELL_GS_WIDTH - 4.5 * S_CELL_GS_WIDTH;
        let cellY = y * S_CELL_GS_WIDTH - 4.5 * S_CELL_GS_WIDTH;
        this.node.x = cellX;
        this.node.y = cellY;
    },
    // update (dt) {},
});
